package com.fengze.business.service.impl;

import java.util.List;

import com.fengze.business.mapper.ReimbursementRecordMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.fengze.business.mapper.ReimbursementListMapper;
import com.fengze.business.domain.ReimbursementList;
import com.fengze.business.service.IReimbursementListService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 报销清单Service业务层处理
 * 
 * @author lug
 * @date 2024-02-28
 */
@Service
public class ReimbursementListServiceImpl implements IReimbursementListService 
{
    @Autowired
    private ReimbursementListMapper reimbursementListMapper;

    @Autowired
    private ReimbursementRecordMapper reimbursementRecordMapper;

    /**
     * 查询报销清单
     * 
     * @param id 报销清单主键
     * @return 报销清单
     */
    @Override
    public ReimbursementList selectReimbursementListById(Long id)
    {
        return reimbursementListMapper.selectReimbursementListById(id);
    }

    /**
     * 查询报销清单列表
     * 
     * @param reimbursementList 报销清单
     * @return 报销清单
     */
    @Override
    public List<ReimbursementList> selectReimbursementListList(ReimbursementList reimbursementList)
    {
        return reimbursementListMapper.selectReimbursementListList(reimbursementList);
    }

    /**
     * 新增报销清单
     * 
     * @param reimbursementList 报销清单
     * @return 结果
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public int insertReimbursementList(ReimbursementList reimbursementList)
    {


        reimbursementRecordMapper.addMoney(reimbursementList.getRecordId(),reimbursementList.getMoney());

        return reimbursementListMapper.insertReimbursementList(reimbursementList);
    }

    /**
     * 修改报销清单
     * 
     * @param reimbursementList 报销清单
     * @return 结果
     */
    @Override
    public int updateReimbursementList(ReimbursementList reimbursementList)
    {
        return reimbursementListMapper.updateReimbursementList(reimbursementList);
    }

    /**
     * 批量删除报销清单
     * 
     * @param ids 需要删除的报销清单主键
     * @return 结果
     */
    @Override
    public int deleteReimbursementListByIds(Long[] ids)
    {
        return reimbursementListMapper.deleteReimbursementListByIds(ids);
    }

    /**
     * 删除报销清单信息
     * 
     * @param id 报销清单主键
     * @return 结果
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public int deleteReimbursementListById(Long id)
    {

        ReimbursementList reimbursementList = reimbursementListMapper.selectReimbursementListById(id);
        reimbursementRecordMapper.subtractionMoney(reimbursementList.getRecordId(),reimbursementList.getMoney());
        return reimbursementListMapper.deleteReimbursementListById(id);
    }
}
